const path = require('path');
const HtmlWebpackPlugin=require('html-webpack-plugin')
module.exports = {
  entry: './src/index.js',
  plugins:[
    new HtmlWebpackPlugin({
      title: 'Caching',
    })
  ],
  output: {
    filename: '[name].[contenthash].js',// contenthash 内容变化时才生成新的hash
    path: path.resolve(__dirname, 'dist'),
    clean: true,
  },
  optimization: {
    moduleIds: 'deterministic',// 防止vendors重复打包
    runtimeChunk: 'single',// 为所有的chunk创建一个runtime bundle
    splitChunks: {
      cacheGroups: {// 将lodash/react等三方库缓存下来
        vendor: {
          test: /[\\/]node_modules[\\/]/,
          name: 'vendors',
          chunks: 'all',
        },
      },
    },
  },
};